<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* .box1 {
            background-color: black;
            width: 300px;
            height: 300px;
        } */

        * {
            box-sizing: border-box;
        }

        .box {
            width: 560px;
            height: 400px;
            background-color: pink;
            margin: 50px auto;
        }

        img {
            width: 100%;
            height: 320px;
            display: block;
        }

        .bottom {
            height: 80px;
            background-color: green;
            padding: 10px 10px 0 10px;

        }

        .bottom p {
            margin: 0;
            color: white;
            margin-bottom: 10px;
        }

        .bottom-ul {
            width: 150px;
            display: flex;
            list-style: none;
            margin: 0;
            padding: 0;
            justify-content: space-between;
            align-items: center;
        }

        .bottom-ul li {
            width: 8px;
            height: 8px;
            margin: 4px;
            border-radius: 50%;
            background: #fff;
            opacity: 0.4;
            cursor: pointer;
        }

        li.lihover {
            width: 12px;
            height: 12px;
            opacity: 1;
        }
    </style>
</head>

<body>
    <div class="box">

        <img src="img/爱与恨德克萨斯.jpg" alt="">
        <div class="bottom">
            <p>啊啊啊啊啊啊啊啊啊啊啊啊啊啊</p>
            <ul class="bottom-ul">
                <li></li>
                <li></li>
                <li></li>
            </ul>
        </div>
    </div>
    <script>

        const sliderData = [
            { url: 'img/娜美.jpg', title: '对人类来说会不会太超前了？', color: 'rgb(100,67,68)' },
            { url: 'img/爱与恨德克萨斯.jpg', title: '开启剑与雪的黑暗传说！', color: 'rgb(43,35,26)' },
            { url: 'img/特雷西亚.jpg', title: '真正的jo厨出现了！', color: 'rgb(36,31,33)' }
        ];


        const pic = document.querySelector('img');
        const p = document.querySelector('p');
        const bc = document.querySelector('.bottom');
        const dots = document.querySelectorAll('.bottom-ul li');


        let nowpt = 0;
        let timer = null;
        function showSlide(idx) {
            pic.src = sliderData[idx].url;
            p.innerHTML = sliderData[idx].title;
            bc.style.backgroundColor = sliderData[idx].color;


            for (let i = 0; i < dots.length; i++) {
                if (i === idx) {
                    dots[i].classList.add('lihover');
                } else {
                    dots[i].classList.remove('lihover');
                }
            }
        }
        const leftBtn = document.createElement('button');
        leftBtn.innerHTML = '👈';
        document.querySelector('.box').appendChild(leftBtn);

        leftBtn.addEventListener('click', function () {
            nowpt--;
            if (nowpt < 0) {
                nowpt = sliderData.length - 1;
            }
            showSlide(nowpt);
        });
        const rightBtn = document.createElement('button');
        rightBtn.innerHTML = '👉';
        document.querySelector('.box').appendChild(rightBtn);

        rightBtn.addEventListener('click', function () {
            nowpt++;
            if (nowpt >= sliderData.length) {
                nowpt = 0;
            }
            showSlide(nowpt);
        });


        function startAuto() {
            stopAuto();
            timer = setInterval(function () {
                nowpt++;
                if (nowpt >= sliderData.length) nowpt = 0;
                showSlide(nowpt);
            }, 1000);
        }

        function stopAuto() {
            clearInterval(timer);
        }


        const box = document.querySelector('.box');
        box.addEventListener('mouseenter', stopAuto);
        box.addEventListener('mouseleave', startAuto);


        showSlide(nowpt);
        startAuto();
    </script>
</body>

</html>